import axios from 'axios';

// 获取需求单列表
export const getDemandList = async (data: any) => {
  try {
    const response = await axios.post('/demand/getDemandList',  {...data});
    console.log(response)
    return {success: true,data:response.data.list,total:response.data.total};
  } catch (error) {
    console.error('获取需求单列表失败', error);
    return { success: false, message: '获取需求单列表失败' };
  }
};

// 保存需求单
export const saveDemand = async (data: any) => {
  try {
    const response = await axios.post('/demand/saveDemand', data);
    return response;
  } catch (error) {
    console.error('保存需求单失败', error);
    return { success: false, message: '保存需求单失败' };
  }
};

// 获取需求单详情
export const getDemandDetail = async (params: any) => {
    try {
      const response = await axios.get('/demand/getDetail?id='+params);
      return response.data;
    } catch (error) {
      console.error('获取详情', error);
      return { success: false, message: '获取详情' };
    }
  };

// 删除需求单
export const deleteDemand = async (data: any) => {
  try {
    const response = await axios.post('/demand/delete', data);
    return response.data;
  } catch (error) {
    console.error('删除需求单失败', error);
    return { success: false, message: '删除需求单失败' };
  }
};

export const getDemandFollowUpList = async (data: any) => {
  try {
    const response = await axios.post('/demandFollowUp/getDemandFollowUpList', data);
    return response;
  } catch (error) {
    console.error('获取需求单列表失败', error);
    return { success: false, message: '获取需求单列表失败' };
  }
};
export const saveDemandComplaint = async (data: any) => {
  try {
    const response = await axios.post('/demandComplaint/saveDemandComplaint', data);
    return response;
  } catch (error) {
    console.error('需求单升级失败', error);
    return { success: false, message: '保存需求单失败' };
  }
};
export const saveDemandFollowUp = async (data: any) => {
    try {
      const response = await axios.post('/demandFollowUp/saveDemandFollowUp', data);
      return response;
    } catch (error) {
      console.error('保存失败', error);
      return { success: false, message: 'err' };
    }
  };
export const sendPaySms = async (data: any) => {
    try {
      const response = await axios.get('/demand/sendPaySms?id='+data);
      return response.data;
    } catch (error) {
      console.error('发起支付失败', error);
      return { success: false, message: '发起支付失败' };
    }
  };

  export const areaCodeGetList = async (params: any) => {
    try {
      const response = await axios.get('/areaCode/getList', { params });
      return {
        data: response.data
      };
    } catch (error) {
      console.error('获取', error);
      return{ success: false, message: '失败' };
    }
  }

  export const demandComplaintClose = async (data: any) => {
    try {
      const response = await axios.post('/demandComplaint/close', { data });
      return {
        data: response.data
      };
    } catch (error) {
      console.error('获取', error);
      return{ success: false, message: '失败' };
   }
  }


  //获取支付链接
  export const getPayUrl = async (params: any) => {
    try {
      const response = await axios.get('/demand/generatePayUrlLink', {params:params});
      return response.data;
    } catch (error) {
      console.error('获取支付链接失败', error);
      return { success: false, message: '获取支付链接失败' };
    }
  };
  // 删除历史跟进计划
  export const deleteDemandFollowUp = async (data: any) => {
    try {
      const response = await axios.post('/demandFollowUp/delete', data);
      return response.data;
    } catch (error) {
      console.error('删除失败', error);
      return { success: false, message: '删除失败' };
    }
  };

  // 上传文件接口
  export const sysUploadFile = async (data: any) => {
    try {
      const response = await axios.post('/system/upload', data);
      return response.data;
    } catch (error) {
      console.error('上传文件失败', error);
      return { success: false, message: '上传文件失败' };
    }
  };

  // 修改需求计划
  export const updateDemandPlan = async (data: any) => {
    try {
      const response = await axios.post('/demand/updateDemandRecord', data);
      return response;
    } catch (error) {
      console.error('修改需求计划失败', error);
      return { success: false, message: '修改需求计划失败' };
    }
  };
  // 短信状态列表
export const getSmsStatusList = async (id: any) => {
  const res = await axios.get(`/demandSmsLog/getList`,{params:{demandId:id}});
  console.log(res,'-res')
  return {
    success: true,
    data: res.data
  }
};

// 确认服务短信
export const confirmServiceSms = (id: any) => {
  return axios.get('/demand/sendReserveSms', {params:{demandId:id}});
};